{extend name="public:base"}
{block name='css'}
<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
{/block}
{block name="js"}
<script src="__PUBLIC__/js/plugins/peity/jquery.peity.min.js"></script>
<script src="__PUBLIC__/js/content.min.js?v=1.0.0"></script>
<script type="text/javascript">
	function delAll(self){
        if ($(self).hasClass('ed')) {
            return false;
        }

        layer.confirm('真的要删除吗？删除后将无法找回！', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $(self).addClass('ed');
            var obj = showMyLoading();
            $.post("{:url('delAll')}", $("#delRecord").serialize(), function(data){
                hideMyLoading(obj);
                layer.msg(data.info);
                if (data.status == 'y') {
                    setTimeout(function(){window.location.reload();},1500);
                } else {
                    $(self).removeClass('ed');
                }
            }, 'json');
        }, function(){

        });
	}

	function sort(self){
        if ($(self).hasClass('ed')) {
            return false;
        }

        $(self).addClass('ed');
        var obj = showMyLoading();
        $.post("{:url('saveSort')}", $("#delRecord").serialize(), function(data){
            hideMyLoading(obj);
            layer.msg(data.info);
            if (data.status == 'y') {
                setTimeout(function(){window.location.reload();},1500);
            } else {
                $(self).removeClass('ed');
            }
        }, 'json');
	}

	function mobile(self){
        if ($(self).hasClass('ed')) {
            return false;
        }

		var newclass_id = $("select[name='newclass_id']").val();
		if(newclass_id == ''){
			layer.msg('请选择需要移动到哪个栏目？');
			return false;
		}

        layer.confirm('确定要移动吗？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $(self).addClass('ed');
            var obj = showMyLoading();
            $.post("{:url('mobile')}?class_id="+newclass_id, $("#delRecord").serialize(), function(data){
                hideMyLoading(obj);
                layer.msg(data.info);
                if (data.status == 'y') {
                    setTimeout(function(){window.location.reload();},1500);
                } else {
                    $(self).removeClass('ed');
                }
            }, 'json');
        }, function(){

        });

	}
	function copy(self){
        if ($(self).hasClass('ed')) {
            return false;
        }

        var newclass_id = $("select[name='newclass_id']").val();
        if(newclass_id == ''){
            layer.msg('请选择需要复制到哪个栏目？');
            return false;
        }

        layer.confirm('确定要复制吗？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $(self).addClass('ed');
            var obj = showMyLoading();
            $.post("{:url('copy')}?class_id="+newclass_id, $("#delRecord").serialize(), function(data){
                hideMyLoading(obj);
                layer.msg(data.info);
                if (data.status == 'y') {
                    setTimeout(function(){window.location.reload();},1500);
                } else {
                    $(self).removeClass('ed');
                }
            }, 'json');
        }, function(){

        });
	}

	function del(self, id){
		if ($(self).hasClass('ed')) {
			return false;
		}

		layer.confirm('真的要删除吗？删除后将无法找回！', {
			btn: ['确定','取消'] //按钮
		}, function(){
			$(self).addClass('ed');
			var obj = showMyLoading();
			$.post("{:url('del')}", {newclass_id:{$newclass_id}, id:id}, function(data){
				hideMyLoading(obj);
				layer.msg(data.info);
				if (data.status == 'y') {
					setTimeout(function(){window.location.reload();},1500);
				} else {
					$(self).removeClass('ed');
				}
			}, 'json');
		}, function(){

		});
	}

    $(function(){
        //全选的实现
        $(".check-all").click(function(){
            $(".ids").prop("checked", this.checked);
        });
        $(".ids").click(function(){
            var option = $(".ids");
            option.each(function(i){
                if(!this.checked){
                    $(".check-all").prop("checked", false);
                    return false;
                }else{
                    $(".check-all").prop("checked", true);
                }
            });
        });

    });
</script>
{/block}
{block name='body'}

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>{$newClassList[$newclass_id]['classname']}</h5>
						<a href="{:url('add',['newclass_id'=>$newclass_id])}" class="btn btn-sm btn-primary pull-right m-t-n-xs">添加文章</a>
                    </div>
                    <div class="ibox-content">
						<div class="row">
                            <div class="col-sm-8 m-b-xs">
								<input type="submit" class="btn btn-sm btn-primary btn-sm btn-danger pull-left" onclick="delAll(this);return false;" value="删除"  />
								<div class="col-sm-4 m-b-xs">
									<select name="newclass_id" class="input-sm  form-control">
										<option value="">选择栏目...</option>
										{foreach name="newClassList" item="li"}
											<option value="{$li.id}" {eq name="$li['end']" value="true"} disabled="disabled" style="background:#ddd;" {/eq} >{$li.html}{$li.classname}</option>
										{/foreach}
									</select>
								</div>
								<button class="btn btn-sm btn-primary"  onclick="mobile(this);return false;" type="submit">移动</button>
								<button class="btn btn-sm btn-primary" onclick="copy(this);return false;" type="submit">复制</button>
                            </div>
							<div class="col-sm-4 m-b-xs">
								<form name="form" action="{:url('index')}"  method="get" >
								<input type="hidden" value="{$newclass_id}" name="newclass_id" />
								<div class="col-sm-12">
                                    <div class="input-group pull-right">
                                        <input type="text" name="keywords" value="{:input('get.keywords')}" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                        <button type="submit"  class="btn btn-sm btn-primary"> 搜索</button>
                                        <a href="{:url('index',['newclass_id' => $newclass_id])}" class="btn btn-sm btn-warning"> 重置</a> </span>
                                    </div>
								</div>
								</form>
                            </div>
                        </div>
						<form name="form" action=""  method="post" id="delRecord" onsubmit="return false;">
                            <input type="hidden" name="newclass_id" value="{$newclass_id}"/>
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>
										<input class="check-all" type="checkbox" value="">
									</th>
                                    <th>标题</th>
                                    <th>排序</th>
                                    <th>添加时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
								{foreach name="list" item="li"}
                                    <tr>
                                        <td><input type="checkbox" class="ids" value="{$li.id}" name="id[]"></td>
                                        <td>{$li.title}</td>
										<td><input type="text"  style="width:60px;text-align:center;" name="{$li.id}" value="{$li.sort}" class="input-sm form-control"></td>
                                        <td>{$li.time|date='Y-m-d H:i:s',###}</td>
                                        <td>
											<a href="{:url('add',['id'=>$li['id'],'newclass_id'=>$newclass_id])}" class="btn btn-success btn-xs edit"><i class="fa fa-edit"></i> 编辑</a>
	                                        <a href="javascript:;" onclick="del(this, {$li['id']});" class="btn btn-danger btn-xs delete"><i class="fa fa-trash-o"></i> 删除</a>
										</td>
                                    </tr>
								{/foreach}
                            </tbody>
							<tfoot>
								<tr>
									<td colspan="2">&nbsp;</td>
                                    <td>
										<button onclick="sort(this);return false;" class="btn btn-sm btn-primary m-t-n-xs" />修改排序</button>
									</td>
                                    <td colspan="8" style="text-align:right;">{$list->render()}</td>
                                </tr>
							</tfoot>
                        </table>
						</form>
                    </div>
                </div>
            </div>
        </div>
        
    </div>
            
</body>
{/block}
